package com.ayu.scalalearn.chapter06

/**
  * @Author 徐林玉
  * @Description Test14TypeJudgment
  * @Date 2022/8/2 14:32
  * @Version 1.0
  */
object Test14TypeJudgment {


  def main(args: Array[String]): Unit = {

    val stu1: PersonTest14 = new StudentTest14("ayu", 18)

    val stu2: PersonTest14 = new StudentTest14("yy", 18)

    //类型判断
    println("stu1 is student : " + stu1.isInstanceOf[StudentTest14])
    println("stu1 is person : " + stu1.isInstanceOf[PersonTest14])

    println("stu2 is student : " + stu2.isInstanceOf[StudentTest14])
    println("stu2 is person : " + stu2.isInstanceOf[PersonTest14])


    //类型转换

    if (stu1.isInstanceOf[StudentTest14]) {
      var newStu = stu1.asInstanceOf[StudentTest14]
      newStu.study()
    }
  }


}


class PersonTest14(var name: String, var age: Int) {


  def sayhi(): Unit = {
    println("person say hi to you")

  }
}


class StudentTest14(name: String, age: Int) extends PersonTest14(name: String, age: Int) {

  override def sayhi(): Unit = {
    println("student say hi to you")
  }

  def study(): Unit = {

    println("student is studding")
  }

}